home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK2.toast / Development Kits (Disc 2) / ScriptX / Documentation / Code Examples from Docs / compguid / twodgrfx / grid.sx next >
Encoding:
Text File  |  1996-05-21  |  1.8 KB  |  100 lines  |  [TEXT/ttxt]

  1. --<<<
  2.  
  3.  
  4.  
  5.  
  6. class grid (TwoDPresenter)
  7. instance variables
  8.  
  9. NofHorizLines:20
  10. NofVertLines:20
  11.  
  12. linev :(new line x1:0 y1:0 x2:0 y2:100)
  13. lineh: (new line x1:0 y1:0 x2:100 y2:0)
  14.  
  15. matrixv:(mutablecopy identityMatrix)
  16. matrixh:(mutablecopy identityMatrix)
  17. horizBrush:(new Brush \
  18.     color:(new RGBColor \
  19.         red:150 blue:150 green:150))
  20. vertBrush:(new Brush \
  21.     color:(new RGBColor \
  22.         red:150 blue:150 green:150))
  23.         
  24. stroke:(new brush color:blackColor)
  25. fill:(new brush color:whitecolor)
  26. end
  27.  
  28.  
  29. method draw self {class Grid} surface clip ->
  30. (
  31.     local globalTrans := self.globalTransform
  32.     
  33.     -- fill in the area
  34.     local fillBrush := self.fill
  35.     if (not fillBrush = undefined) do
  36.     fill surface self.bbox clip globalTrans fillBrush
  37.     
  38.     local horizBrush := self.horizBrush
  39.     local vertBrush := self.vertBrush
  40.     
  41.     local linev := self.linev
  42.     linev.y2 := self.height
  43.     local lineh := self.lineh
  44.     lineh.x2 := self.width
  45.     
  46.     horizTrans := self.height / self.NofHorizLines
  47.     vertTrans := self.width / self.NofVertLines
  48.     
  49.     -- local matrixv := mutableCopy globalTrans
  50.     local matrixv := self.matrixv
  51.     setTo matrixv globalTrans
  52.     
  53.     -- local matrixh := mutableCopy globalTrans
  54.     local matrixh := self.matrixh
  55.     setTo matrixh globalTrans
  56.     
  57.     for i in 1 to (self.NofVertLines - 1)
  58.     do
  59.     (translate matrixv vertTrans 0
  60.     fill surface linev clip matrixv vertBrush
  61.     )
  62.     for i in 1 to (self.NofHorizLines - 1) do
  63.     (
  64.     translate matrixh 0 horizTrans
  65.     fill surface lineh clip matrixh horizBrush
  66.     )
  67.     
  68.     -- stroke the outline
  69.     local strokeBrush := self.stroke
  70.     
  71.     
  72.     if (not strokeBrush = undefined) do
  73.         stroke surface self.bbox clip globalTrans strokeBrush
  74.         
  75.     
  76. )
  77.     
  78. w := new window
  79. w.width := 500
  80. w.height := 400
  81.  
  82. show w
  83.  
  84.  
  85. global grid1 := new grid boundary:(new rect x2:200 y2:100)
  86.  
  87.  append w grid1
  88.  
  89.  grid1.x := 50
  90.  grid1.y := 50
  91.  
  92.  -->>>
  93.  
  94.  grid1.width := 200
  95.  grid1.height := 200
  96.  grid1.width := 100
  97.  grid1.height := 100
  98.  
  99.  
  100.